package com.lkx.kafka.monitor.config;

import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.core.KafkaAdmin;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

@Configuration
public class KafkaConfig {

    @Value("${spring.kafka.bootstrap-servers}")
    private String bootstrapServers;

    @Value("${kafka.monitor.admin.timeout}")
    private int adminTimeout;

    @Bean
    public AdminClient adminClient(KafkaAdmin kafkaAdmin) {
        Properties props = new Properties();
        props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
        props.put(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, adminTimeout);
        props.put(AdminClientConfig.RETRIES_CONFIG, 3);
        return AdminClient.create(kafkaAdmin.getConfigurationProperties());
    }
}